package com.example.cqh_votesys.handler;

import com.example.cqh_votesys.exception.BaseException;
import com.example.cqh_votesys.pojo.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Author: pollux
 * @CreateTime: 2024-06-30
 * @Description: 全局异常处理器
 * @Version: 1.0
 */

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    /**
     * @param ex 自己定义的业务异常基类
     * @description: 捕获全局抛出的异常基类
     * @return:
     * @author: pollux
     * @date: 2024/6/30 13:59
     */
    @ExceptionHandler
    public Result excetionHandler(BaseException ex){
        log.error("异常信息为：{}",ex.getMessage());
        return Result.error(ex.getMessage());
    }
}





















